using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

//球的初始移动
public class Ball : MonoBehaviour
{
    public new Rigidbody2D rigidbody2D { get; private set; }
    public float speed = 500f;
    
    private void Awake()
    {
        this.rigidbody2D = GetComponent<Rigidbody2D>();
    }

    private void Start()
    {
        RestBall();
    }

    public void RestBall()
    {
        this.transform.position = Vector2.zero;
        this.rigidbody2D.velocity = Vector2.zero;
        
        Invoke(nameof(SetRandomTrajectory),1f);//延迟1f执行
    }

    private void SetRandomTrajectory()
    {
        Vector2 force = Vector2.zero;
        force.x = Random.Range(-1f,1f);
        force.y = -1f;
        rigidbody2D.AddForce(force.normalized * this.speed);

    }
}
